﻿using MVVMOpenChildWindow.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVVMOpenChildWindow.ViewModels
{
    public class MainViewModel : INotifyPropertyChanged
    {
        private int _value;

        public int Value
        {
            get { return _value; }
            set { _value = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value)));}
        }

        public Command BtnCommand { get; set; }

        public MainViewModel()
        {
            BtnCommand = new Command((obj) =>
            {
                #region // 窗口弹窗逻辑
                //var childWindowViewModel = new ChildWindowViewModel();
                //childWindowViewModel.MyProperty = Value;
                ////WindowProvider.ShowDialog("ChilidWindow", childWindowViewModel);

                ////如何从子窗口返回数据到主窗口： ChildViewModel->MainViewModel
                ////1.子窗口打开后，编辑完成，保存按钮、取消按钮，加到MainViewModel判断子窗口的返回状态
                ////2、最终数据不在子VM处理，返回到主VM再处理，保存，回退

                //if (WindowProvider.ShowDialog("ChilidWindow", childWindowViewModel))
                //{
                //    this.Value = childWindowViewModel.MyProperty;
                //} 
                #endregion





               
            });

            #region //方法委托逻辑
            ActionManager.Register<object>(new Action<object>(DoAction), "AAA");



            ActionManager.Register<object>(new Func<object>(DoFunc), "BBB");
            #endregion
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        private void BtnClick(object? parameter)
        {

            
        }

        void DoAction(object obj)
        {

        }

        private object DoFunc()
        {
            return this.Value;
        }
    }
}
